package com.report.controller;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.report.dto.request.MemberRuleReq;
import com.report.dto.response.MemberRuleRes;
import com.report.entity.Rule;
import com.report.service.IMemberRuleService;
import com.zmh.framework.config.BaseCommonInterface;
import com.zmh.framework.util.Result;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author summer
 * @since 2024/06/26 23:21:57
 */
@RestController
@RequestMapping("/memberRule")
@AllArgsConstructor
public class MemberRuleController  implements BaseCommonInterface<MemberRuleReq, MemberRuleRes> {

    private final IMemberRuleService memberRuleService;

    @Override
    public Result<String> save(@Valid MemberRuleReq memberRuleReq) {
        memberRuleService.saveOrUpdate(Convert.convert(Rule.class,memberRuleReq));
        return Result.successResult();
    }

    @Override
    public Result<String> del(Integer id) {
        memberRuleService.removeById(id);
        return Result.successResult();
    }

    @Override
    public Result<Page<MemberRuleRes>> lists(MemberRuleReq memberRuleReq) {
        Page<MemberRuleRes> page=memberRuleService.lists(memberRuleReq);
        return Result.successResult(page);
    }

    @Override
    public Result<MemberRuleRes> findById(Integer id) {
        MemberRuleRes memberRuleRes=memberRuleService.findById(id);
        return Result.successResult(memberRuleRes);
    }

    @Override
    public Result<String> batchDel(List<MemberRuleRes> list) {
        return null;
    }
}
